﻿////关配置信息
//var RemoteLinkAddress = "http://220.166.61.4:8088/GSMS";
//var RemoteLinkAddress = "http://192.168.199.187:8080/GSMS";
//var RemoteLinkAddress = "http://222.196.35.4:8088/GSMS";
var RemoteLinkAddress = "http://222.196.35.35:9080/GSMS";

var AddFlag = -1;
// 基础信息Dialog
var WebDataZoneList = [{
	"city": "涪城区",
	"code": "FCQ",
	"updatetime": "",
}, {
	"city": "游仙区",
	"code": "YXQ",
	"updatetime": "",
}, {
	"city": "三台县",
	"code": "STX",
	"updatetime": "",
}];

//
var orderFieldMap = [{
	"fieldname": "AMOUNT",
	"valuename": "数量",
}, {
	"fieldname": "TRADE_NAME",
	"valuename": "原始名称",
}, {
	"fieldname": "INTERNAL_TYPE",
	"valuename": "内部商品类型",
}, {
	"fieldname": "UNIT_NAME",
	"valuename": "计量单位",
}, {
	"fieldname": "UNIT_PRICE",
	"valuename": "单价",
}, {
	"fieldname": "INTERNAL_NAME",
	"valuename": "内部商品名",
}, {
	"fieldname": "SUM",
	"valuename": "总价",
}];

var typeOptions = [
	////公共部分基础信息
	{
		"type": "department",
		"title": "部门信息",
		"save": "/department/save.do",
		"del": "/department/delete.do",
		"list": "/department/listall.do",
		"id": "ID",
		"name": "NAME",
	},

	/////市场部分基础信息
	{
		"type": "boostcard",
		"title": "市场部分商户卡证信息",
		"save": "/market/card/save.do",
		"del": "/market/card/delete.do",
		"list": "/market/card/listall.do",
		"id": "ID",
		"name": "NAME"
	}, {
		"type": "region",
		"title": "市场区域信息",
		"save": "/market/region/save.do",
		"del": "/market/region/delete.do",
		"list": "/market/region/listall.do",
		"id": "ID",
		"name": "NAME"
	}, {
		"type": "marketchargetype",
		"title": "市场收费类型",
		"save": "/market/chargetype/save.do",
		"del": "/market/chargetype/delete.do",
		"list": "/market/chargetype/listall.do",
		"id": "ID",
		"name": "NAME"
	},
	{
		"type": "shorttype",
		"title": "市场部分短期合同类型",
		"save": "/market/shorttype/save.do",
		"del": "/market/shorttype/delete.do",
		"list": "/market/shorttype/listall.do",
		"id": "ID",
		"name": "NAME"
	},
	{
		"type": "duty",
		"title": "市场部分责任书",
		"save": "/market/duty/save.do",
		"del": "/market/duty/delete.do",
		"list": "/market/duty/listall.do",
		"id": "ID",
		"name": "NAME"
	}, {
		"type": "regiontype",
		"title": "市场部分区域类型",
		"save": "/market/regiontype/save.do",
		"del": "/market/regiontype/delete.do",
		"list": "/market/regiontype/listall.do",
		"id": "ID",
		"name": "NAME"
	}, {
		"type": "businesslicensetype",
		"title": "市场部分营业执照类型",
		"save": "/businesslicensetype/save.do",
		"del": "/businesslicensetype/delete.do",
		"list": "/businesslicensetype/listall.do",
		"id": "ID",
		"name": "NAME"
	},
	{
		"type": "devicetype",
		"title": "市场部分设备类型",
		"save": "/market/devicetype/save.do",
		"del": "/market/devicetype/delete.do",
		"list": "/market/devicetype/listall.do",
		"id": "ID",
		"name": "NAME"
	},
	//////气调库部分基础信息
	{
		"type": "frozenchargetype",
		"title": "气调库收费类型",
		"save": "/frozen/chargetype/save.do",
		"del": "/frozen/chargetype/delete.do",
		"list": "/frozen/chargetype/listall.do",
		"id": "ID",
		"name": "TYPE"
	},
	{
		"type": "repairtype",
		"title": "气调库维修类型",
		"save": "/frozen/repairtype/save.do",
		"del": "/frozen/repairtype/delete.do",
		"list": "/frozen/repairtype/listall.do",
		"id": "ID",
		"name": "TYPE"
	},
	//物流部分基础信息
	{
		"type": "internaltradetype",
		"title": "物流部分内部商品分类",
		"save": "/logistics/internaltradetype/save.do",
		"del": "/logistics/internaltradetype/delete.do",
		"list": "/logistics/internaltradetype/listall.do",
		"id": "ID",
		"name": "INTERNAL_TYPE"
	}, {
		"type": "customertype",
		"title": "物流部分用户组",
		"save": "/logistics/customertype/save.do",
		"del": "/logistics/customertype/delete.do",
		"list": "/logistics/customertype/listall.do",
		"id": "ID",
		"name": "CUSTOMER_TYPE"
	}, {
		"type": "providertype",
		"title": "物流部分供应商类型",
		"save": "/logistics/providertype/save.do",
		"del": "/logistics/providertype/delete.do",
		"list": "/logistics/providertype/listall.do",
		"id": "ID",
		"name": "PROVIDERTYPE"
	}, {
		"type": "delivertype",
		"title": "物流部分配送方式类型",
		"save": "/logistics/delivertype/save.do",
		"del": "/logistics/delivertype/delete.do",
		"list": "/logistics/delivertype/listall.do",
		"id": "ID",
		"name": "DELIVERY_METHOD"
	}, {
		"type": "logisticsstorehouse",
		"title": "物流部分库房名称",
		"save": "/logistics/storehouse/save.do",
		"del": "/logistics/storehouse/delete.do",
		"list": "/logistics/storehouse/listall.do",
		"id": "ID",
		"name": "NAME"
	}, {
		"type": "logisticslevel",
		"title": "物流部分产品质量",
		"save": "/logistics/level/save.do",
		"del": "/logistics/level/delete.do",
		"list": "/logistics/level/listall.do",
		"id": "ID",
		"name": "LEVEL"
	}
];
//此函数查找orderfieldmap中的数据进行映射
function searchOrderFieldMap(data) {
	for(var i = 0; i < orderFieldMap.length; i++) {
		if(data == orderFieldMap[i].fieldname) {
			return orderFieldMap[i].valuename;
		}
	}
	return undefined;
}

function deepCopy(o) {
	var isArray = o instanceof Array;
	var isObject = o instanceof Object;
	if(!isObject) return o;
	var n = (isArray ? [] : {});
	for(var k in o) n[k] = deepCopy(o[k]);
	return n;
}

function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
		" " + date.getHours() + seperator2 + date.getMinutes() +
		seperator2 + date.getSeconds();
	return currentdate;
}

function extend(Child, Parent) {
	var F = function() {}; //申明一个局部的类来打断父类prototype的改变对目前类的影响
	F.prototype = Parent.prototype;
	Child.prototype = new F();
	Child.prototype.constructor = Child;
	Child.uber = Parent.prototype; //可以使用父类的方法
}

function getNowFormatDate2() {
	var date = new Date();
	var seperator1 = "/";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
	return currentdate;
}
////检测手机号码是否符合规范
function checkPhoneNumber(_phonenumber) {
	var regular_phone = /^1[3|4|5|7|8]\d{9}$/;
	var phone = _phonenumber;
	var tip = "验证成功";
	if(phone == "") {
		tip = "电话号码为空";
	}
	if(!regular_phone.test(phone)) {
		tip = "电话号码格式不对";
	}
	return tip;
}

/////检测车牌号码是否符合规范
function checkCarNo(_carno) {
	var regular_car = /^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$/;
	var tip = "验证成功";
	if(_carno == "") {
		tip = "车牌号码为空";
	}
	if(!regular_car.test(_carno)) {
		tip = "车牌号格式不对";
	}
	return tip;
}

function checkMail(mailStr) {　
	var tip = "验证成功";　　　
	var Regex = /^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/;　
	if(mailStr == "") {　　　　
		tip = "邮件地址不能为空";　　
	}　
	if(!Regex.test(mailStr)) {　　
		tip = "邮件格式不正确";　
	}　　
	return tip;
}
var TIME_YEAR = 0;
var TIME_MONTH = 1;
var TIME_DAY = 2;

function CalTimeLimit(startTime, endTime, Type) {
	var res;
	var s = 0;
	var reg = new RegExp("/", "g");
	var _start = startTime.replace(reg, "");
	var _end = endTime.replace(reg, "");
	if(parseFloat(_start) > parseFloat(_end)) {
		$.messager.alert("提示", "时间填写错误!");
		return -1;
	}
	switch(Type) {
		case TIME_YEAR:
			s = 1000 * 60 * 60 * 24 * 30 * 12;
			break;
		case TIME_MONTH:
			s = 1000 * 60 * 60 * 24 * 30;
			break;
		case TIME_DAY:
			s = 1000 * 60 * 60 * 24;
			break;
	}
	res = Math.ceil(Math.abs((Date.parse(endTime) - Date.parse(startTime))) / s);
	return res;
}

function IdentityCodeValid(code) {
	var city = {
		11: "北京",
		12: "天津",
		13: "河北",
		14: "山西",
		15: "内蒙古",
		21: "辽宁",
		22: "吉林",
		23: "黑龙江 ",
		31: "上海",
		32: "江苏",
		33: "浙江",
		34: "安徽",
		35: "福建",
		36: "江西",
		37: "山东",
		41: "河南",
		42: "湖北 ",
		43: "湖南",
		44: "广东",
		45: "广西",
		46: "海南",
		50: "重庆",
		51: "四川",
		52: "贵州",
		53: "云南",
		54: "西藏 ",
		61: "陕西",
		62: "甘肃",
		63: "青海",
		64: "宁夏",
		65: "新疆",
		71: "台湾",
		81: "香港",
		82: "澳门",
		91: "国外 "
	};
	var tip = "验证成功";
	if(!/^\d{17}(\d|x)$/i.test(code)) {
		//	if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)) {
		tip = "身份证号格式错误";
	} else if(!city[code.substr(0, 2)]) {
		tip = "地址编码错误";
	} else {
		//18位身份证需要验证最后一位校验位
		if(code.length == 18) {
			code = code.split('');
			//∑(ai×Wi)(mod 11)
			//加权因子
			var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
			//校验位
			var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
			var sum = 0;
			var ai = 0;
			var wi = 0;
			for(var i = 0; i < 17; i++) {
				ai = code[i];
				wi = factor[i];
				sum += ai * wi;
			}
			var last = parity[sum % 11];
			if(parity[sum % 11] != code[17]) {
				tip = "校验位错误";
			}
		}
	}
	return tip;
}

function check_time(_time) {
	var regular_time = /((^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(10|12|0?[13578])([-\/\._])(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(11|0?[469])([-\/\._])(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(0?2)([-\/\._])(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)([-\/\._])(0?2)([-\/\._])(29)$)|(^([3579][26]00)([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][0][48])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][0][48])([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][2468][048])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][2468][048])([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][13579][26])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][13579][26])([-\/\._])(0?2)([-\/\._])(29)$))/;
	var timecheck = _time;
	var tip = "验证成功";
	if(timecheck.length == 0) {
		tip = "时间位数不正确"
	}
	if(!regular_time.test(timecheck)) {
		tip = "时间格式不正确"
	}
	return tip;
}
//相关函数
function Clearnav() {
	var pp = $('#wnav').accordion('panels');
	$.each(pp, function(i, n) {
		if(n) {
			var t = n.panel('options').title;
			$('#wnav').accordion('remove', t);
		}
	});
	pp = $('#wnav').accordion('getSelected');
	if(pp) {
		var title = pp.panel('options').title;
		$('#wnav').accordion('remove', title);
	}
}

function addNav(data) {
	$.each(data, function(i, sm) {
		var menulist = "";
		menulist += '<ul>';
		$.each(sm.menus, function(j, o) {
			menulist += '<li><div><a ref="' + o.menuid + '" href="#" rel="' + o.url + '" ><span class="icon ' + o.icon + '" >&nbsp;</span><span class="nav">' + o.menuname + '</span></a></div></li> ';
		});
		menulist += '</ul>';
		$('#wnav').accordion('add', {
			title: sm.menuname,
			content: menulist,
			iconCls: 'icon ' + sm.icon
		});
	});
	var pp = $('#wnav').accordion('panels');
	var t = pp[0].panel('options').title;
	$('#wnav').accordion('select', t);

}

// 初始化左侧
function InitLeftMenu() {

	hoverMenuItem();
	//  $("button#demo").click(function(){$("img").hide()})
	$('#wnav li a').click(function() {
		var tabTitle = $(this).children('.nav').text();
		var url = $(this).attr("rel");
		var menuid = $(this).attr("ref");
		var icon = getIcon(menuid, icon);
		addTab(tabTitle, url, icon);
		$('#wnav li div').removeClass("selected");
		$(this).parent().addClass("selected");
	});

}

/**
 * 菜单项鼠标Hover
 */
function hoverMenuItem() {
	$(".easyui-accordion").find('a').hover(function() {
		$(this).parent().addClass("hover");
	}, function() {
		$(this).parent().removeClass("hover");
	});
}

// 获取左侧导航的图标
function getIcon(menuid) {
	var icon = 'icon ';
	$.each(_menus, function(i, n) {
		$.each(n, function(j, o) {
			$.each(o.menus, function(k, m) {
				if(m.menuid == menuid) {
					icon += m.icon;
					return false;
				}
			});
		});
	});
	return icon;
}

function addTab(subtitle, url, icon) {
	if(!$('#tabs').tabs('exists', subtitle)) {
		$('#tabs').tabs('add', {
			title: subtitle,
			content: createFrame(url),
			closable: true,
			icon: icon
		});
	} else {
		$('#tabs').tabs('select', subtitle);
		$('#mm-tabupdate').click();
	}
	tabClose();
}

function createFrame(url) {
	var s = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
	return s;
}

function tabClose() {
	/* 双击关闭TAB选项卡 */
	$(".tabs-inner").dblclick(function() {
		var subtitle = $(this).children(".tabs-closable").text();
		$('#tabs').tabs('close', subtitle);
	});
	/* 为选项卡绑定右键 */
	$(".tabs-inner").bind('contextmenu', function(e) {
		$('#mm').menu('show', {
			left: e.pageX,
			top: e.pageY
		});

		var subtitle = $(this).children(".tabs-closable").text();

		$('#mm').data("currtab", subtitle);
		$('#tabs').tabs('select', subtitle);
		return false;
	});
}
// 绑定右键菜单事件
function tabCloseEven() {
	// 刷新
	$('#mm-tabupdate').click(function() {
		var currTab = $('#tabs').tabs('getSelected');
		var url = $(currTab.panel('options').content).attr('src');
		$('#tabs').tabs('update', {
			tab: currTab,
			options: {
				content: createFrame(url)
			}
		});
	});
	// 关闭当前
	$('#mm-tabclose').click(function() {
		var currtab_title = $('#mm').data("currtab");
		$('#tabs').tabs('close', currtab_title);
	});
	// 全部关闭
	$('#mm-tabcloseall').click(function() {
		$('.tabs-inner span').each(function(i, n) {
			var t = $(n).text();
			$('#tabs').tabs('close', t);
		});
	});
	// 关闭除当前之外的TAB
	$('#mm-tabcloseother').click(function() {
		$('#mm-tabcloseright').click();
		$('#mm-tabcloseleft').click();
	});
	// 关闭当前右侧的TAB
	$('#mm-tabcloseright').click(function() {
		var nextall = $('.tabs-selected').nextAll();
		if(nextall.length == 0) {
			// msgShow('系统提示','后边没有啦~~','error');
			alert('后边没有啦~~');
			return false;
		}
		nextall.each(function(i, n) {
			var t = $('a:eq(0) span', $(n)).text();
			$('#tabs').tabs('close', t);
		});
		return false;
	});
	// 关闭当前左侧的TAB
	$('#mm-tabcloseleft').click(function() {
		var prevall = $('.tabs-selected').prevAll();
		if(prevall.length == 0) {
			alert('到头了，前边没有啦~~');
			return false;
		}
		prevall.each(function(i, n) {
			var t = $('a:eq(0) span', $(n)).text();
			$('#tabs').tabs('close', t);
		});
		return false;
	});

	// 退出
	$("#mm-exit").click(function() {
		$('#mm').menu('hide');
	});
}

// 弹出信息窗口 title:标题 msgString:提示信息 msgType:信息类型 [error,info,question,warning]
function msgShow(title, msgString, msgType) {
	$.messager.alert(title, msgString, msgType);
}

// 本地时钟

//获取传入的页面参数
function getID() {
	urlinfo = window.location.href; //获取当前页面的url
	len = urlinfo.length; //获取url的长度
	offset = urlinfo.indexOf("?"); //设置参数字符串开始的位置
	if(offset == -1) {
		return undefined;
	}
	newsidinfo = urlinfo.substr(offset, len) //取出参数字符串 这里会获得类似“id=1”这样的字符串
	newsids = newsidinfo.split("="); //对获得的参数字符串按照“=”进行分割
	newsid = newsids[1]; //得到参数值
	newsname = newsids[0]; //得到参数名字
	return newsid;
}

function getMultiID() {
	urlinfo = window.location.href; //获取当前页面的url
	len = urlinfo.length; //获取url的长度
	offset = urlinfo.indexOf("?"); //设置参数字符串开始的位置
	if(offset == -1) {
		return undefined;
	}
	newsidinfo = urlinfo.substr(offset + 1, len) //取出参数字符串 这里会获得类似“id=1”这样的字符串
	var newinfo = newsidinfo.split("&");
	var MultiID = {};
	for(var i = 0; i < newinfo.length; i++) {
		newsids = newinfo[i].split("="); //对获得的参数字符串按照“=”进行分割
		MultiID[newsids[0]] = newsids[1];
	}
	return MultiID;
}
//构建基本的dialog
function constructDialog(dlgname, ptitle, pwidth, pheight) {
	var html = dlgname.html();
	AddDialog = window.parent.$(html).appendTo(window.top.document.body);
	AddDialog.dialog({
		modal: true,
		title: ptitle,
		cache: true,
		closable: true,
		draggable: true,
		width: pwidth,
		height: pheight,
		onClose: function() {
			$('#dg').datagrid('reload');
		},
	}).dialog('close');
}

////用于新增基础类型信息
function constructcomboDialog(dlgname, ptitle, comboObj) {
	var html = dlgname.html();
	var DICT_DIALOG_WIDTH = 485;
	var DICT_DIALOG_HEIGHT = 417;
	AddDialog = window.parent.$(html).appendTo(window.top.document.body);
	AddDialog.dialog({
		modal: true,
		title: ptitle,
		cache: true,
		closable: true,
		draggable: true,
		width: DICT_DIALOG_WIDTH,
		height: DICT_DIALOG_HEIGHT,
		onClose: function() {
			comboObj.combobox('reload');
		},
	}).dialog('close');
}

function getMap() { //初始化map_，给map_对象增加方法，使map_像个Map  
	var map_ = new Object();
	//属性加个特殊字符，以区别方法名，统一加下划线_  
	map_.put = function(key, value) {
		map_[key] = value;
	}
	map_.get = function(key) {
		return map_[key];
	}
	map_.remove = function(key) {
		delete map_[key];
	}
	map_.keyset = function() {
		var ret = "";
		for(var p in map_) {
			if(typeof p == 'string' && p.substring(p.length - 1) == "_") {
				ret += ",";
				ret += p;
			}
		}
		if(ret == "") {
			return ret.split(","); //empty array  
		} else {
			return ret.substring(1).split(",");
		}
	}
	return map_;
}

//给easyui的tabs添加了鼠标移动到相应的位置的hover效果
function Tabs_Hover() {
	var tabs = $("#div_tabs").tabs().tabs('tabs');
	for(var i = 0; i < tabs.length; i++) {
		tabs[i].panel('options').tab.unbind().bind('mouseenter', {
			index: i
		}, function(e) {
			$("#div_tabs").tabs('select', e.data.index);
		});
	}
}

function AddTabIn(pTitle, Obj, src) {
	var pSrc = "";
	if(Obj.tabs('exists', pTitle)) {
		Obj.tabs('close', pTitle);
	}
	pSrc = "<iframe id='ifmcontent' scrolling='auto' frameborder='0'  src='" + src + "' style='width:100%;height:100%;'></iframe>";
	Obj.tabs("add", { //获取到父窗体信息
		title: pTitle,
		content: pSrc,
		closable: true,
		tools: [{
			iconCls: 'icon-mini-refresh',
			handler: function() {
				var currTab = Obj.tabs('getSelected'); //获得当前tab
				var url = $(currTab.panel('options').content).attr('src');
				Obj.tabs('update', {
					tab: currTab,
					options: {
						content: createFrame(url)
					}
				});
			}
		}]
	});
}

function iFrameHeight(_ObjID) {
	var ifm = document.getElementById(_ObjID);
	var subWeb = document.frames ? document.frames[_ObjID].document : ifm.contentDocument;
	if(ifm != null && subWeb != null) {
		ifm.height = subWeb.body.scrollHeight;
		ifm.width = subWeb.body.scrollWidth;

	}
}

//在页面中添加脚注，底部一些基本信息的显示
function addFooter(obj_id) {
	var footer_content = "<table cellpadding='5' id='footertable'> <tr><td>备注 </td> <td colspan ='7'> <input type = 'text' name='MEMO' id='input_MEMO' style ='width:100%' class = 'easyui-textbox' /></td> <td></td> <td></td> <td></td> <td></td> <td></td></tr><tr><td>制单人 </td><td><input type='text' id='input_CREATE_MAN' style='border:none;' readonly='readonly' class = 'easyui-textbox'/ > </td><td>审核人</td> <td> <input type = 'text'name='AUDITOR' id='input_AUDITOR' style='border:none;' readonly='readonly' class = 'easyui-textbox'/> </td><td>审核日期 </td><td><input type = 'text'  name='AUDITOR_TIME' id='input_AUDITOR_TIME' style='border:none;' readonly='readonly' class = 'easyui-datebox'/ > </td><td>打印次数 </td> <td> <input type ='text' name='PRINTCOUNT' id='input_PRINTCOUNT' style='border:none;' readonly='readonly' class = 'easyui-textbox'/ > </td></tr></table>";
	obj_id.append(footer_content);
}

function getFooterData(data) {
	$("#footertable .easyui-textbox").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(data[substr] != undefined) {
			$(this).textbox("setValue", data[substr]);
		}
	});
}

function addDialogFooter(obj_id) {
	obj_id.empty();
	obj_id.css('background-color', '#D2E0F2');
	var dialog_footer_content = "<div id=\"dialogfooter\" style=\"background-color:#D2E0F2;height:100px;margin: 10px auto\"><div style=\"width: 70%;height: 90%;float: left;\"><table cellpadding=\"5\" style=\"width: 97%;height: 97%;margin: 0px auto;\"><tr><td >备注</td><td colspan=\"7\"><input class=\"easyui-textbox\" type=\"text\" name=\"MEMO\" id=\"input_MEMO\" style=\"width: 85%;\" /></td></tr><tr><td>制单人</td><td><input type=\"text\" name=\"CREATE_MAN\" id=\"input_CREATE_MAN\" data-options=\"disabled:true\" class=\"easyui-textbox\"/></td><td>审核人</td><td><input type=\"text\" name=\"AUDITOR\" id=\"input_AUDITOR\" data-options=\"disabled:true\" class =\"easyui-textbox\" /></span></td><td>审核时间</td><td><input type=\"text\" name=\"AUDITOR_TIME\" id=\"input_AUDITOR_TIME\" class = 'easyui-datebox' data-options=\"disabled:true\" /></td></tr></table></div><div id=\"verifydisplay\" style=\"width: 30%;height: 50px;float: right;text-align: center\"></div></div>";
	obj_id.append(dialog_footer_content);
}
///Dialog中没有审核的footer 
function addDialogFooterWithOutVerify(obj_id) {
	obj_id.empty();
	obj_id.css('background-color', '#D2E0F2');
	var dialog_footer_content = "<table cellpadding='5' style='margin: auto;width: 85%;'><tr><td>备注 </td><td colspan='3'> <input type='text' name='MEMO' id='input_MEMO' class='easyui-textbox' style='width:100%' /></td></tr><tr><td width='10%'>制单人 </td><td width='35%'><span  name='CREATE_MAN' id='input_CREATE_MAN' style='width:100%' class = 'easyui-textbox'></span> </td><td width='10%'>制单时间 </td><td width='35%'><span name='CREATE_TIME' id='input_CREATE_TIME' style='width:100%' class = 'easyui-datebox'></span> </td></tr></table>";

	obj_id.append(dialog_footer_content);
}

function getDialogFooterData(data) {
	$("#dialogfooter span[id]").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(typeof(data[substr]) != "undefined") {
			$(this).html(data[substr]);
		}
	});
	$("#dialogfooter .easyui-textbox").each(function(index) {
		var s = $(this).attr("id");
		var substr = deletePreSymbol("input_", s);
		if(data[substr] != undefined) {
			$(this).textbox("setValue", data[substr]);
		}
	});
}

function getFormData(data) {
	if(typeof(data) != "undefined") {
		$("#ff .easyui-textbox").each(function(index) {
			var s = $(this).attr("id");
			var substr = deletePreSymbol("input_", s);
			if(typeof(data[substr]) != "undefined") {
				$(this).textbox("setValue", data[substr]);
			}
		});
		$("#ff .easyui-combobox").each(function(index) {
			var s = $(this).attr("id");
			var substr = deletePreSymbol("input_", s);
			if(typeof(data[substr]) != "undefined") {
				$(this).combobox("setValue", data[substr]);
			}
		});
		$("#ff .easyui-datebox").each(function(index) {
			var s = $(this).attr("id");
			var substr = deletePreSymbol("input_", s);
			if(typeof(data[substr]) != "undefined") {
				$(this).textbox("setValue", data[substr]);
			}
		});
		$("#ff .easyui-numberbox").each(function(index) {
			var s = $(this).attr("id");
			var substr = deletePreSymbol("input_", s);
			if(typeof(data[substr]) != "undefined") {
				$(this).textbox("setValue", data[substr]);
			}
		});
	} else {
		console.log("该网页无数据！");
	}

}

function getPrintData(data) {
	if(typeof(data) != "undefined") {
		$("input").each(function(index) {
			var s = $(this).attr("id");
			var substr = deletePreSymbol("input_", s);
			if(typeof(data[substr]) != "undefined") {
				$(this).val(data[substr]);
			}
		});

	} else {
		console.log("该网页无数据！");
	}

}

function submitDialogFormData() {
	var _data = {};
	$("#ff input").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $("input[name=subtr]").val();
	});
	$("#ff span").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $("span[name=subtr]").val();
	});
	return _data;
}

function submitFormData() { ///获取需要提交的数据
	var _data = {};
	$("#ff .easyui-combobox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).combobox("getValue").trim();
	});
	$("#ff .easyui-textbox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).textbox("getValue").trim();
	});
	$("#ff .easyui-datebox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).datebox("getValue").trim();
	});
	$("#ff .easyui-numberbox").each(function(index) {
		var s = $(this).attr("id");
		var subtr = deletePreSymbol("input_", s);
		_data[subtr] = $(this).textbox("getValue").trim();
	});
	return _data;
}

////删除 id 中input_的前缀
function deletePreSymbol(_presymbol, _str) {
	var len = _str.length;
	var pre_symbol_len = _presymbol.length;
	var _substr = _str.substring(pre_symbol_len, len);
	return _substr;
}

//构建单据明细中的ToolBar,
var RECEIPT_FRONT_SYMBOL = 1;
var RECEIPT_NEXT_SYMBOL = 2;
var RECEIPT_ADD_SYMBOL = 4;
var RECEIPT_SAVE_SYMBOL = 8;
var RECEIPT_DELETE_SYMBOL = 16;
var RECEIPT_VERIFY_SYMBOL = 32;
var RECEIPT_UNVERIFY_SYMBOL = 64;
var RECEIPT_SEARCH_SYMBOL = 128;
var RECEIPT_PRINT_SYMBOL = 256;
var RECEIPT_CHARGE_SYMBOL = 512;
var RECEIPT_EXPORT_SYMBOL = 1024;
var RECEIPT_SEARCHALL_SYMBOL = 2048;

function AddReceiptsToolBar(type, newdata) {
	var data = [{
		"icon": "icon-left",
		"func": "frontpage()",
		"functionname": "上张"
	}, {
		"icon": "icon-right",
		"func": "nextpage()",
		"functionname": "下张"
	}, {
		"icon": "icon-add",
		"func": "newdata()",
		"functionname": "新建单据"
	}, {
		"icon": "icon-save",
		"func": "save()",
		"functionname": "保存单据"
	}, {
		"icon": "icon-remove",
		"func": "deletedata()",
		"functionname": "删除单据"
	}, {
		"icon": "icon-to_do",
		"func": "verifydata()",
		"functionname": "审核单据"
	}, {
		"icon": "icon-redo",
		"func": "unverifydata()",
		"functionname": "弃审单据"
	}, {
		"icon": "icon-search",
		"func": "searchmore()",
		"functionname": "查询"
	}, {
		"icon": "icon-print",
		"func": "print()",
		"functionname": "打印单据"
	}, {
		"icon": "icon-usermanagement",
		"func": "charge()",
		"functionname": "收费"
	}, {
		"icon": "icon-save",
		"func": "exportExcel()",
		"functionname": "导出"
	}, {
		"icon": "icon-undo",
		"func": "redodata()",
		"functionname": "查看所有数据"
	}]
	var content = "";
	var s;

	/////验证权限
	var currLocation = subStrBaseUrl(window.location.href); //当前页面
	_data = localStorage.getItem('currRight');
	if(_data != null) {
		var authorityList = JSON.parse(_data);
		var authorityArray = $.grep(authorityList, function(value) {
			return value.name == currLocation;
		});
		if(authorityArray.length > 0) //表明存在权限配置
		{
			var _right = authorityArray[0];
			var validataType = RECEIPT_FRONT_SYMBOL + RECEIPT_NEXT_SYMBOL + RECEIPT_SEARCH_SYMBOL;
			validataType += RECEIPT_PRINT_SYMBOL;
			validataType += RECEIPT_CHARGE_SYMBOL;
			if(_right.hasAdd == true) {
				validataType += RECEIPT_ADD_SYMBOL;
			}
			if(_right.hasEdit == true) {
				validataType += RECEIPT_SAVE_SYMBOL;
			}
			if(_right.hasDel == true) {
				validataType += RECEIPT_DELETE_SYMBOL;
			}
			if(_right.hasSh == true) {
				validataType += RECEIPT_VERIFY_SYMBOL;
			}
			if(_right.hasQs == true) {
				validataType += RECEIPT_UNVERIFY_SYMBOL;
			}
			type = type & validataType;
		}
	} else {
		authorityCheck();
	}

	////////////////
	for(var i = 0; i < data.length; i++) {
		s = type & (1 << i);
		if(s != 0) {
			content += "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\"  iconCls=\"" + data[i].icon + "\" plain='true' onclick=\"" + data[i].func + "\">" + data[i].functionname + "</a>";
		}
	}
	////处理附加的功能
	for(var i = 0; i < newdata.length; i++) {
		content += "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\"  iconCls=\"" + newdata[i].icon + "\" plain='true' onclick=\"" + newdata[i].func + "\">" + newdata[i].functionname + "</a>";
	}
	return content;
}
//用于生成edatagrid中的工具栏
function AddDetailToolBar(type) {
	var DetailToolBarData = [{
		text: '新增明细',
		iconCls: 'icon-add',
		handler: function() {
			$('#tt').edatagrid('addRow');
		}
	}, {
		text: '取消',
		iconCls: 'icon-cancel',
		handler: function() {
			$('#tt').edatagrid('cancelRow');
		}
	}, {
		text: '删除明细',
		iconCls: 'icon-remove',
		handler: function() {
			$('#tt').edatagrid('destroyRow');
		}
	}, {
		text: '收费',
		iconCls: 'icon-charge',
		handler: function() {
			charge();
		}
	}, {
		text: '保存',
		iconCls: 'icon-save',
		handler: function() {
			save();
		}
	}, {
		text: '摊位启用',
		iconCls: 'icon-startBoost',
		handler: function() {
			startBoost();
		}
	}, {
		text: '摊位停用',
		iconCls: 'icon-stopBoost',
		handler: function() {
			stopBoost();
		}
	}, {
		text: '退费',
		iconCls: 'icon-returnFee',
		handler: function() {
			returnFee();
		}
	}];
	var data = [];
	var s;
	for(var i = 0; i < DetailToolBarData.length; i++) {
		s = type & (1 << i);
		if(s != 0) {
			data.push(DetailToolBarData[i]);
		}
	}
	return data;

}

var TOOLBAR_ADD = 1;
var TOOLBAR_EDITOR = 2;
var TOOLBAR_DELETE = 4;
var TOOLBAR_PRINT = 8;
var TOOLBAR_LOAD = 16;
var TOOLBAR_REDO = 32;
var TOOLBAR_FINDMORE = 64;
//type为二进制数字 如全部显示为63
function AddToolBar(type) {
	var data = [{
		"icon": "icon-add",
		"func": "newdata()",
		"functionname": "新增"
	}, {
		"icon": "icon-edit",
		"func": "editdata()",
		"functionname": "修改"
	}, {
		"icon": "icon-remove",
		"func": "destroy()",
		"functionname": "删除"
	}, {
		"icon": "icon-print",
		"func": "print()",
		"functionname": "打印"
	}, {
		"icon": "icon-save",
		"func": "loaddata()",
		"functionname": "导出"
	}, {
		"icon": "icon-undo",
		"func": "redodata()",
		"functionname": "查看所有数据"
	}, {
		"icon": "icon-large-chart",
		"func": "findmore()",
		"functionname": "相关信息"
	}, {
		"icon": "icon-usermanagement",
		"func": "tenantcharge()",
		"functionname": "租户明细账"
	}]
	var content = "";
	var s;
	///权限验证
	var currLocation = subStrBaseUrl(window.location.href); //当前页面
	_data = localStorage.getItem('currRight');
	if(_data != null) {
		var authorityList = JSON.parse(_data);
		var authorityArray = $.grep(authorityList, function(value) {
			return value.name == currLocation;
		});
		if(authorityArray.length > 0) //表明存在权限配置
		{
			var _right = authorityArray[0];
			var validataType = TOOLBAR_FINDMORE + TOOLBAR_REDO + TOOLBAR_PRINT;
			if(_right.hasAdd == true) {
				validataType += TOOLBAR_ADD;
			}
			if(_right.hasEdit == true) {
				validataType += TOOLBAR_EDITOR;
			}
			if(_right.hasDel == true) {
				validataType += TOOLBAR_DELETE;
			}
			if(_right.hasDc == true) {
				validataType += TOOLBAR_LOAD;
			}
			type = type & validataType;
		}
	} else {
		authorityCheck();
	}
	///////////
	for(var i = 0; i < data.length; i++) {
		s = type & (1 << i);
		if(s != 0) {
			content += "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\"  iconCls=\"" + data[i].icon + "\" plain='true' onclick=\"" + data[i].func + "\">" + data[i].functionname + "</a>";
		}
	}
	return content;
}

function isJson(obj) {
	if(obj.length > 0) {
		isjson = true;
	} else {
		isjson = false;
	}
	return isjson;
}

//通用的删除接口
function CreateDestroy(select, addr) {
	var row = select.datagrid('getSelected');
	if(row) {
		$.messager.confirm('Confirm', '是否删除', function(r) {
			if(r) {
				$.post(RemoteLinkAddress + addr, {
						TENANT_ID: row.TENANT_ID,
						AUTHORIZATION: auth
					},
					function(result) {
						if(result.msg == "success") {
							$('#dg').datagrid('reload'); // reload the user data
							$.messager.alert({ // show error message
								title: '成功',
								msg: '删除成功'
							});
						} else {
							$.messager.alert({ // show error message
								title: 'Error',
								msg: result.msg
							});
						}
					},
					'json');
			}
		});
	} else {
		$.messager.alert('提示信息', '请选择需要删除的数据!');
	}
}

////object 数据完整性检查
function checkObjectDataIntegrity(obj, KeyField, omitField) {
	for(var i = 0; i < obj.length; i++) {
		var m = obj[i];
		if(m[KeyField] != undefined) {
			for(s in m) {
				if(s != omitField && m[s] == undefined) {
					return false;
				}
			}
		}
	}
	return true;
}

function logProcess(data, type) {
	var str = "";
	switch(type) {
		case "add":
			str = "[新增记录]:";
			break;
		case "delete":
			str = "[删除记录]:";
			break;
	}
	for(var s in data) {
		if(searchOrderFieldMap(s) != undefined) {
			str += searchOrderFieldMap(s) + ":" + data[s] + " ";
		}
	}
	str += ";";
	return str;
}

function searchParent(name) {
	for(var i = 0; i < window.parent.length; i++) {
		if(getLastsymol(window.parent[i].location.pathname) == name) {
			return window.parent[i];
		}
	}
}

function getLastsymol(str) {
	var index = str.lastIndexOf("\/");
	str = str.substring(index + 1, str.length);
	return str;
}

function verifyStatus(isVerify, displayImg) {
	var unverifyImg = '<img src="../../../images/checkfailed.png" width="100%"/>';
	var verifyImg = '<img src="../../../images/checked.png" width="100%"/>';
	if(displayImg) {
		var notreviewImg = $("#notreview");
	}

	var status = "";
	var img = "";
	switch(isVerify) {
		case "":
		case "0":
		case 0:
			status = "未审核";
			img = unverifyImg;
			break;
		case "1":
		case 1:
			status = "审核通过";
			img = verifyImg;
			break;

	}
	if(displayImg) {
		notreviewImg.empty();
		notreviewImg.append(img);
	}
	return status;
}

function verifyStatus_Market(isVerify, displayImg) {
	var unverifyImg = '<img src="../../../images/checkedfailedMarket.png" width="40%"/>';
	var verifyImg = '<img src="../../../images/checkedMarket.png" width="40%"/>';
	if(displayImg) {
		var verifydisplayImg = $("#verifydisplay");
	}

	var status = "";
	var img = "";
	switch(isVerify) {
		case "":
		case "0":
		case 0:
			status = "未审核";
			img = unverifyImg;
			break;
		case "1":
		case 1:
			status = "审核通过";
			img = verifyImg;
			break;

	}
	if(displayImg) {
		verifydisplayImg.empty();
		verifydisplayImg.append(img);
	}
	return status;
}

function refreshTabs(obj, _title) {
	var s = {};
	s.title = _title;
	obj.tabs('select', _title); //获得当前tab
	var currTab = obj.tabs('getSelected');
	if(currTab != null) {
		var url = $(currTab.panel('options').content).attr('src');
		obj.tabs('update', {
			tab: currTab,
			options: {
				content: createFrame(url)
			}
		});
	} else {
		console.log("没有选中TABS");
	}
}

function subStrBaseUrl(_url) {
	var spritIndex = _url.lastIndexOf("\/"); //斜杠所在的位置
	var htmlIndex = _url.lastIndexOf("\.html"); //.html所在的位置
	var res = _url.substring(spritIndex + 1, htmlIndex);
	return res;

}

function constructSpecialCondition(obj) {
	for(s in obj) {
		var res = s + "=" + obj[s];
		return res;
	}
}

function authorityCheck() //如果出现用户登录信息丢失的情况,应该跳转到登录页面
{
	//	$.parent.location.href = "UI/Common/Login/login.html";
	//	console.log("登录信息丢失"); //此处应该要跳转到登录界面
}

/*还原查询时候的信息*/
function checkAllData(address) {
	var _url = RemoteLinkAddress + address;
	$('#dg').datagrid('options').url = _url;
	$('#dg').datagrid('reload');
}

function isEnglish(s) {
	var ret = false;
	var reg = /^[A-Za-z]+$/;
	if(reg.test(s)) //判断是否符合正则表达式
	{
		return true;
	}
	return ret;
}

function handleSaveReturnData(result) {
	var res = new Object;
	var rev = new Array();
	rev = result.msg.split(";");
	res.ID = rev[1];
	res.ORDER_NO = rev[2];
	getFormData(res);
	return res.ID;
}

Array.prototype.unique = function(data) {
	data = data || [];
	var a = {};
	len = data.length;
	for(var i = 0; i < len; i++) {
		var v = data[i];
		if(typeof(a[v]) == 'undefined') {
			a[v] = 1;
		}
	};
	data.length = 0;
	for(var i in a) {
		data[data.length] = i;
	}
	return data;
}

function lockButton(state) {
	if(state == "lock") {
		$(".easyui-linkbutton").each(function(index) {
			$(this).linkbutton('disable');
		});
	}
	if(state == "unlock") {
		$(".easyui-linkbutton").each(function(index) {
			$(this).linkbutton('enable');
		});
	}
}